//
//  OrderedTeacherCell.m
//  SDSY
//
//  Created by 蓝布鲁 on 2017/4/15.
//  Copyright (c) 2017 蓝布鲁. All rights reserved.
//

#import "OrderedTeacherCell.h"
#import "OrderedTeacherModel.h"
#import "OrderTeacherButton.h"
#import "TeacherOrderTimeModel.h"

@interface OrderedTeacherCell()

@property (nonatomic,retain)UIImageView *headerImageView;       // 导师头像
@property (nonatomic,retain)UILabel *teacherNameLabel;          // 导师名
@property (nonatomic,retain)UILabel *orderTimeLabel;            // 已预约的时间


@end

@implementation OrderedTeacherCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setupView];
    }
    return self;
}

#pragma mark - 自定义方法
-(void)setupView {
    // 导师头像
    self.headerImageView = [[UIImageView alloc] init];
    self.headerImageView.layer.masksToBounds = true;
    self.headerImageView.layer.cornerRadius = 25;
    [self.contentView addSubview:self.headerImageView];

    // 导师名
    self.teacherNameLabel = [[UILabel alloc] init];
    self.teacherNameLabel.font = [UIFont systemFontOfSize:15];
    [self.contentView addSubview:self.teacherNameLabel];

    // 导师预约时间
    self.orderTimeLabel = [[UILabel alloc] init];
    self.orderTimeLabel.font = [UIFont systemFontOfSize:12];
    [self.contentView addSubview:self.orderTimeLabel];

    // 布局视图
    self.headerImageView.sd_layout.topSpaceToView(self.contentView,10).leftSpaceToView(self.contentView,10).heightIs(50).widthIs(50);
    self.teacherNameLabel.sd_layout.topEqualToView(self.headerImageView).leftSpaceToView(self.headerImageView,5).heightIs(18);
    [self.teacherNameLabel setSingleLineAutoResizeWithMaxWidth:200];
    self.orderTimeLabel.sd_layout.leftEqualToView(self.teacherNameLabel).bottomEqualToView(self.headerImageView).heightIs(15);
    [self.orderTimeLabel setSingleLineAutoResizeWithMaxWidth:200];

    [self setupAutoHeightWithBottomView:self.headerImageView bottomMargin:10];
}

- (void)setModel:(OrderedTeacherModel *)model {
    _model = model;
    // 导师头像
    [self.headerImageView sd_setImageWithURL:[NSURL URLWithString:self.model.img_url] placeholderImage:[UIImage imageNamed:@"avatar_default"]];

    // 导师名
    self.teacherNameLabel.text = self.model.name;

    // 导师预约次数
    self.orderTimeLabel.text = [NSString stringWithFormat:@"%@ %@ ~ %@", [self.model.date formatDate],self.model.starttime,self.model.endtime];

    // 设置预约按钮
    OrderTeacherButton *button = [[OrderTeacherButton alloc] initWithFrame:CGRectMake(0, 0, 20, 25)];
    button.userInteractionEnabled = true;
    button.code = self.model.stauts;
    [button sizeToFit];
    [button addTarget:self action:@selector(orderButtonTapped) forControlEvents:UIControlEventTouchUpInside];
    self.accessoryView = button;
}


#pragma mark - 网络请求
#pragma mark - 事件监听
-(void)orderButtonTapped {
    if(self.callBack != nil){
        self.callBack(self.model);
    }
}
@end
